﻿using CrawlerApp.Infrastructure.Enums;
using System;
using System.Collections.Generic;
using System.Linq;

namespace CrawlerApp.Core.Entities.BookAggregate
{
    public class BookResource
    {
        public ResourceType Type { get; private set; } = ResourceType.WinRar;
        public string Verifer { get; private set; }
        public string Length { get; private set; }
        public ResourceFormat Format { get; private set; } = ResourceFormat.Txt;
        public string Progress { get; private set; }
        public ResourceStatus Status { get; private set; } = ResourceStatus.Finish;
        private readonly List<string> _urls = new List<string>();
        public IReadOnlyCollection<string> Urls => _urls.AsReadOnly();

        public BookResource(string verifer = null, string length = null, ResourceFormat format = ResourceFormat.Txt, string progress = null, ResourceStatus status = ResourceStatus.Finish)
        {
            Verifer = verifer;
            Length = length;
            Format = format;
            Progress = progress;
            Status = status;
        }

        public void AddUrl(string url)
        {
            if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url));

            if(!_urls.Contains(url))
            {
                _urls.Add(url);
            }
        }

        public void AddRangeUrl(List<string> urls)
        {
            if (urls == null) throw new ArgumentNullException(nameof(urls));

            urls.ForEach(url => AddUrl(url));
        }
    }
}
